package ketanglianxi;

public class BankAccount {
    // 私有成员变量，外部不能直接访问
    private double balance;

    // 构造函数
    public BankAccount(double initialBalance) {
        this.balance = initialBalance;
    }

    // 获取余额
    public double getBalance() {
        return balance;
    }

    // 存款方法
    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
            System.out.println("存款成功，当前余额: " + balance);
        } else {
            System.out.println("存款金额必须大于0");
        }
    }

    // 取款方法
    public void withdraw(double amount) {
        if (amount <= 0) {
            System.out.println("取款金额必须大于0");
        } else if (amount > balance) {
            System.out.println("余额不足，取款失败");
        } else {
            balance -= amount;
            System.out.println("取款成功，当前余额: " + balance);
        }
    }
}